package com.example.myController;

import com.example.entity.UserInfo;
import com.example.sources.annotation.*;
import com.example.sources.modelView.ModelAndView;
import com.example.sources.myenum.RequestMethod;
import com.example.service.UserService;

import javax.servlet.http.HttpServletRequest;

/**
 * Created by zhu on 2016/5/9.
 */
@MyController
public class RequestController {

    @MyResources(name = "UserServiceImpl")
    private UserService userService;

    @MyResponseString
    @MyRequestMapping(path = "/zhu/test1/",method = RequestMethod.GET)
    public String testA(HttpServletRequest httpServletRequest){
        userService.login();
        return "xx";
    }

    @MyResponseString
    @MyRequestMapping(path = "/zhu/test2",method = RequestMethod.GET)
    public String testAs(HttpServletRequest httpServletRequest){

        return "xx";
    }

    @MyRequestMapping(path = "/zhu/test1/{id}",method = RequestMethod.GET)
        public ModelAndView testOne(@PathVariable String id,@RequestParam String name){
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("test1.zhu");
        modelAndView.setViewMap("id",String.valueOf(id));
        modelAndView.setViewMap("name", name);
        UserInfo userInfo = new UserInfo();
        userInfo.setId(1L);
        userInfo.setPassword("123");
        userInfo.setType(1);
        userInfo.setUsername("呵呵哒");
        modelAndView.setObjectMap("userinfo",userInfo);
        return modelAndView;
    }

    @MyResponseString
    @MyRequestMapping(path = "/zhu/test/{id}",method = RequestMethod.GET)
    public String ids(@PathVariable String id,@RequestParam String name,HttpServletRequest httpServletRequest){

        return id+"! "+name+"! "+httpServletRequest.getQueryString();
    }

    @MyRequestMapping(path = "/zhu/test",method = RequestMethod.POST)
    public String testOnea(){
        return "cao.html";
    }

    @MyRequestMapping(path = "/zhu/html_test",method = RequestMethod.GET)
    public String testOneaa(){
        return "xxx.html";
    }

}
